package com.itheima.service.impl;

import com.itheima.mapper.SetmealDao;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SetmealServiceImpl implements SetmealService {
    @Autowired
    private SetmealDao setmealDao;
    @Override
    public List<Setmeal> getSetmeal() {
        List<Setmeal> setmeals=setmealDao.getSetmeal();
        return setmeals;
    }

    @Override
    public Setmeal findById(Long id) {
        Setmeal setmeal=setmealDao.findById(id);
        List<CheckGroup> checkGroups=setmealDao.findByIdcheckGroups(id);
        setmeal.setCheckGroups(checkGroups);
        for (int i = 0; i < checkGroups.size(); i++) {
            Integer checkGroupId=checkGroups.get(i).getId();
            List<CheckItem> checkItems=setmealDao.findByIdcheckItems(checkGroupId);
            checkGroups.get(i).setCheckItems(checkItems);
        }
        return setmeal;
    }
}
